package View.dianming;

import Service.DormService;
import Service.ServiceImpl.DormServiceImpl;
import View.Index.Index_admin;
import domain.Dorm;
import domain.User;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Vector;

public class dianming extends JFrame {

    public dianming(User user){
        init();
        componentInit(user);
    }
    String[] item;
    public void init(){
        this.setTitle("宿舍点名");
        this.setSize(600,400);
        this.setResizable(true);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(null);
    }
    public void componentInit(User user){
        //------------------JLabel--------------------
        JLabel label1= new JLabel();
        label1.setText("请选择要查看的宿舍");
        label1.setBounds(122,65,119,30);


        //------------------JButton--------------------
        JButton button1= new JButton();
        button1.setText("点击查看详情");
        button1.setBounds(93,226,110,27);
        JButton button2= new JButton();
        button2.setText("退出");
        button2.setBounds(295,227,95,27);




        //------------------JComboBox--------------------
        DormService service = new DormServiceImpl();
        List<Dorm> dorms = service.dormList();
        Vector<String> item= new Vector<>();
        for (int i = 0; i < dorms.size(); i++) {
            Dorm dorm = dorms.get(i);
            item.add(dorm.getDormnum());
        }
        System.out.println(item);

        JComboBox comboBox1= new JComboBox(item);
        comboBox1.setBounds(261,67,120,26);

        this.add(label1);
        this.add(button1);
        this.add(button2);
        this.add(comboBox1);

        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String selectedItem = (String) comboBox1.getSelectedItem();
                new show(user,selectedItem).setVisible(true);
            }
        });

        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new Index_admin(user).setVisible(true);
            }
        });
    }
}
